package com.qczl.pme.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qczl.pme.dao.FingerDao;
import com.qczl.pme.dao.MettingDao;
import com.qczl.pme.dao.SignDao;
import com.qczl.pme.entity.PMEMetting;
import com.qczl.pme.entity.PMESign;
import com.qczl.pme.service.FingerService;

/**
 * 指纹机业务逻辑层接口
 * @作者:SongR
 * @日期:2017年9月25日上午11:48:58
 */
@Service
public class FingerServiceImpl implements FingerService{

	@Autowired
	FingerDao dao;
	@Autowired
	SignDao signdao;
	@Autowired
	MettingDao mettingdao;
	
	/**
	 * 指纹机通知
	 */@Override
	public void notifyV1(String userid, String mettingid) throws Exception{
		PMEMetting metting = mettingdao.get("from PMEMetting where id="+mettingid);
		if(metting.getStatus()==2){//会议没开始
			PMESign sign = signdao.get("from PMESign where personid="+userid +" and state=0 and mettingid="+mettingid);
			if(sign==null){
				sign = new PMESign();
				sign.setMettingid(new Long(mettingid));
				sign.setPersonid(new Long(userid));
				sign.setSigntime(new Date());
				sign.setSigntypeid(new Long(1));
				sign.setState(0);
				signdao.saveOrUpdate(sign);
			}
		}else if(metting.getStatus()==1){//开会中
			PMESign sign = signdao.get("from PMESign where personid="+userid +" and state=0 and mettingid="+mettingid);
			if(sign==null){
				sign = new PMESign();
				sign.setMettingid(new Long(mettingid));
				sign.setPersonid(new Long(userid));
				sign.setSigntime(new Date());
				sign.setSigntypeid(new Long(1));
				sign.setState(0);
				signdao.saveOrUpdate(sign);
			}
		}
	}

}
